
import numpy as np
def main():
    demo()

def softmax(a):
    c = np.max(a)
    exp_a = np.exp(a - c)  # 溢出对策
    sum_exp_a = np.sum(exp_a)
    y = exp_a / sum_exp_a
    return y

def demo():
    a = np.array([0.3, 2.9, 4.0])
    y = softmax(a)
    print(y)

if __name__ == "__main__":
    main()

